package com.jfinal.weixin.model;

import com.jfinal.plugin.activerecord.Model;

/**
 * Created by 446705260@qq.com on 16/5/4.
 * chengzhichao
 */
public class Score extends Model<Score> {
    public final static Score dao  = new Score();

    public boolean isAddedToday(int userid){
        int size = super.find("SELECT id FROM `score` where concat(CURDATE(),' 00:00:00') < time and concat(CURDATE(),' 23:59:59') > time and userid=?", new Object[]{userid}).size();
        return size>0;
    }



    public boolean addScore(String openid){
        User user = User.dao.getUserByOpenid(openid);
        int score = user.getInt("score");
        user.set("score",score+1);
        Score score1 = new Score();
        score1.set("userid",user.getInt("id"));
        score1.set("lastscore",user.getInt("score"));
        score1.set("openid",user.get("openid"));
        score1.save();
        return user.update();
    }


}
